<!-- 银行配置 -->
<template>
  <div class='bank_list'>
    <Row :gutter="16" class="top_warp">
      <Col span="3" offset="21" class="cityList_moudle_footer">
      <Button type="primary" @click="addBank" v-if="unlocking('0102010501')">新建银行</Button>
      </Col>
    </Row>
    <dt-grid ref="table" :onFetch='onFetch' />
    <!-- 编辑弹窗 -->
    <edit-modal ref="edit" @success='onSuccess' />
  </div>
</template>

<script>
  import bankApi from '@/biz/buildingManagement/bank'
  import column from './opt/columns'
  import dt from '@dt/dt'
  import editModal from './components/edit.vue'
  export default {
    components: { editModal },
    data() {
      return {
        housesId: dt.buildInfo().housesId,
      }
    },
    methods: {
      onFetch(data) {
        return bankApi.GetBankList({ housesId: this.housesId }).then((res) => {
          if (res) {
            return res
          }
        })
      },
      onSuccess() {
        this.$refs.table.fetch()
      },
      //编辑 新建
      addBank() {
        let data = {
          title: '新建银行',
          bankName: '',
          subBankName: '',
        }
        this.$refs.edit.show(data)
      },
      changeBank(obj) {
        let data = Object.assign({}, obj)
        data.title = '编辑银行'
        this.$refs.edit.show(data)
      },
      //更改状态
      changeStatus(obj) {
        let params = {
          bankId: obj.bankId,
          bankName: obj.bankName,
          bankStatus: obj.bankStatus == 1 ? 2 : 1,
          subBankName: obj.subBankName,
          housesId: this.housesId,
        }
        bankApi.saveOrEditBank(params).then((res) => {
          this.$Message.success('修改成功')
          this.onSuccess()
        })
      },
      //删除
      delChannel(obj) {
        this.$Modal.confirm({
          title: '确认删除该银行？',
          okText: '确定',
          cancelText: '取消',
          onOk: () => {
            let params = {
              bankId: obj.bankId,
              bankName: obj.bankName,
              subBankName: obj.subBankName,
              housesId: this.housesId,
            }
            bankApi.delBanck(params).then((res) => {
              this.$Message.success('删除成功')
              this.onSuccess()
            })
          },
        })
      },
    },
    mounted() {
      this.$refs.table.init(this, new column(this))
      this.$refs.table.fetch()
    },
  }
</script>
<style lang='scss' scoped>
  .bank_list {
    .top_warp {
      margin-bottom: 20px;

      .total_num {
        font-size: 18px;
      }
    }

    .cityList_moudle_footer {
      display: flex;
      justify-content: space-around;
    }
  }
</style>